﻿using System;
using System.Xml.Serialization;
using System.Collections.Generic;
using System.Net;
using GolfSigma.Inventory.Model;

namespace GolfSigma.Inventory
{
    /// <summary>
    /// Amazon SQS  Exception provides details of errors 
    /// returned by Amazon SQS  service
    /// </summary>
    public class InventoryException : Exception
    {
        private String message = null;
        private HttpStatusCode statusCode = default(HttpStatusCode);
        private String errorCode = null;
        private String errorType = null;
        private String requestId = null;
        private String xml = null;

        /// <summary>
        /// Constructs InventoryException with message
        /// </summary>
        /// <param name="message">Overview of error</param>
        public InventoryException(String message)
        {
            this.message = message;
        }

        /// <summary>
        /// Constructs InventoryException with message and status code
        /// </summary>
        /// <param name="message">Overview of error</param>
        /// <param name="statusCode">HTTP status code for error response</param>
        public InventoryException(String message, HttpStatusCode statusCode) : this(message)
        {
            this.statusCode = statusCode;
        }


        /// <summary>
        /// Constructs InventoryException with wrapped exception
        /// </summary>
        /// <param name="t">Wrapped exception</param>
        public InventoryException(Exception t) : this(t.Message, t) { }

        /// <summary>
        /// Constructs InventoryException with message and wrapped exception
        /// </summary>
        /// <param name="message">Overview of error</param>
        /// <param name="t">Wrapped exception</param>
        public InventoryException(string message, Exception t) : base(message, t)
        {
            this.message = message;
            if (t is InventoryException)
            {
                InventoryException ex = (InventoryException)t;
                this.statusCode = ex.StatusCode;
                this.errorCode = ex.ErrorCode;
                this.errorType = ex.ErrorType;
                //this.requestId = ex.RequestId;
                this.xml = ex.XML;
            }
        }


        /// <summary>
        /// Constructs InventoryException with information available from service
        /// </summary>
        /// <param name="message">Overview of error</param>
        /// <param name="statusCode">HTTP status code for error response</param>
        /// <param name="errorCode">Error Code returned by the service</param>
        /// <param name="errorType">Error type. Possible types:  Sender, Receiver or Unknown</param>
        /// <param name="requestId">Request ID returned by the service</param>
        /// <param name="xml">Compete xml found in response</param>
        public InventoryException(string message, HttpStatusCode statusCode, string errorCode, string errorType, string requestId, string xml) : this(message, statusCode)
        {
            this.errorCode = errorCode;
            this.errorType = errorType;
            this.requestId = requestId;
            this.xml = xml;
        }

        /// <summary>
        /// Gets and sets of the ErrorCode property.
        /// </summary>
        public string ErrorCode
        {
            get { return this.errorCode; }
        }

        /// <summary>
        /// Gets and sets of the ErrorType property.
        /// </summary>
        public string ErrorType
        {
            get { return this.errorType; }
        }

        /// <summary>
        /// Gets error message
        /// </summary>
        public override string Message
        {
            get { return this.message; }
        }


        /// <summary>
        /// Gets status code returned by the service if available. If status
        /// code is set to -1, it means that status code was unavailable at the
        /// time exception was thrown
        /// </summary>
        public HttpStatusCode StatusCode
        {
            get { return this.statusCode; }
        }

        /// <summary>
        /// Gets XML returned by the service if available.
        /// </summary>
        public string XML
        {
            get { return this.xml; }
        }

        ///// <summary>
        ///// Gets Request ID returned by the service if available.
        ///// </summary>
        //public string RequestId
        //{
        //    get { return this.requestId; }
        //}

    }
}
